package editor.main;

import java.awt.Dimension;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import editor.modelo.EditorSpace;
import editor.modelo.LandMark;


public class LandmarkPanel extends JPanel implements EntityEditor<LandMark> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2361931850397956122L;
	private LandMark entidad;
	private JTextField txtName;
	private JTextField txtX;
	private JTextField txtY;
	private JComboBox<LandMark.Tipo> comboBoxTipos;
	private JTextField txtAltura;
	/**
	 * Create the panel.
	 */
	public LandmarkPanel() {
		setPreferredSize(new Dimension(218, 145));
		setLayout(null);
		
		comboBoxTipos = new JComboBox<LandMark.Tipo>(LandMark.Tipo.values());
		comboBoxTipos.setBounds(66, 11, 140, 20);
		add(comboBoxTipos);
		
		JLabel lblTipo = new JLabel("Tipo:");
		lblTipo.setHorizontalAlignment(SwingConstants.RIGHT);
		lblTipo.setBounds(10, 14, 46, 14);
		add(lblTipo);
		
		txtName = new JTextField();
		txtName.setBounds(66, 37, 140, 20);
		add(txtName);
		txtName.setColumns(10);
		
		JLabel lblNombre = new JLabel("Nombre:");
		lblNombre.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNombre.setBounds(10, 39, 46, 14);
		add(lblNombre);
		
		JLabel lblCentroX = new JLabel("Centro X:");
		lblCentroX.setHorizontalAlignment(SwingConstants.RIGHT);
		lblCentroX.setBounds(10, 66, 46, 14);
		add(lblCentroX);
		
		txtX = new JTextField();
		txtX.setEditable(false);
		txtX.setColumns(10);
		txtX.setBounds(66, 64, 140, 20);
		add(txtX);
		
		JLabel lblCentroY = new JLabel("Centro Y:");
		lblCentroY.setHorizontalAlignment(SwingConstants.RIGHT);
		lblCentroY.setBounds(10, 93, 46, 14);
		add(lblCentroY);
		
		txtY = new JTextField();
		txtY.setEditable(false);
		txtY.setColumns(10);
		txtY.setBounds(66, 91, 140, 20);
		add(txtY);
		
		txtAltura = new JTextField();
		txtAltura.setEditable(false);
		txtAltura.setEnabled(false);
		txtAltura.setColumns(10);
		txtAltura.setBounds(66, 118, 140, 20);
		add(txtAltura);
		
		JLabel lblAltura = new JLabel("Altura:");
		lblAltura.setHorizontalAlignment(SwingConstants.RIGHT);
		lblAltura.setBounds(10, 120, 46, 14);
		add(lblAltura);
		
		//comboBoxTipos.setModel(new Model)

	}

	public void setEntity(LandMark entity) {
		this.entidad = entity;
		this.txtName.setText(entidad.getName());
		//this.txtAltura.setText(String.valueOf(entidad.getHeight()));
		this.comboBoxTipos.setSelectedItem(entity.getTipo());
		this.txtX.setText(String.valueOf(entidad.getCentro().getX()));
		this.txtY.setText(String.valueOf(entidad.getCentro().getY()));
		
	}

	public LandMark getEntity() {
		return entidad;
	}

	public void applyChanges() {
	//	entidad.getCentro().Float.valueOf(txtX));
		entidad.setName(this.txtName.getText());
		entidad.setTipo((LandMark.Tipo)this.comboBoxTipos.getSelectedItem());
	/*	try{
			entidad.setHeight(Integer.valueOf(txtAltura.getText()));
		}catch(Exception ex){}*/
		
	}

	public boolean validateEntity() {
		
		return true;
	}
}
